package com.yjt.fresh.activity;

import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseResultEntity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.MainActivity;
import com.yjt.fresh.R;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.example.entity.resulte.SubjectResulte;

import java.util.List;

import butterknife.BindView;

public class AtyLoginDemo extends BaseSimpleActivity {
    //手机号码
    @BindView(R.id.login_mobile_et)
    EditText mMobileEt;
    //密码
    @BindView(R.id.login_pwd_et)
    EditText mPwdEt;
    //忘记密码
    @BindView(R.id.login_forget_pwd_tv)
    TextView mForgetPwdTv;
    //登录按钮
    @BindView(R.id.login_btn_tv)
    TextView mLoginBtnTv;
    @BindView(R.id.login_register_tv)
    TextView mRegisterTv;
    @BindView(R.id.login_qq_login_iv)
    ImageView mQQLoginIv;
    @BindView(R.id.login_wechat_login_iv)
    ImageView mWechateLoginIv;
    @BindView(R.id.login_agreenment_tv)
    TextView mGreenmentTv;


    @Override
    protected int getContentView() {
        return R.layout.aty_login;
    }

    @Override
    protected void initViews() {
        mLoginBtnTv=getViewById(R.id.login_btn_tv);
//        SubjectPostApi postEntity = new SubjectPostApi(simpleOnNextListener,this,true,true,true);
//        postEntity.setAll(true);
//        HttpManager manager = HttpManager.getInstance();
//        manager.doHttpDeal(postEntity);
    }


    //   回调一一对应
    HttpOnNextListener simpleOnNextListener = new HttpOnNextListener<List<BaseResultEntity>>() {
        @Override
        public void onNext(List<BaseResultEntity> subjects) {
            Log.e("tag", "onNext: "+subjects);
//            tvMsg.setText("网络返回：\n" + subjects.toString());
        }

        @Override
        public void onCacheNext(String cache) {
            /*缓存回调*/
            Gson gson=new Gson();
            java.lang.reflect.Type type = new TypeToken<BaseResultEntity<List<SubjectResulte>>>() {}.getType();
            BaseResultEntity resultEntity= gson.fromJson(cache, type);
//            tvMsg.setText("缓存返回：\n"+resultEntity.getData().toString() );
        }

        /*用户主动调用，默认是不需要覆写该方法*/
        @Override
        public void onError(Throwable e) {
            super.onError(e);
//            tvMsg.setText("失败：\n" + e.toString());
        }

        /*用户主动调用，默认是不需要覆写该方法*/
        @Override
        public void onCancel() {
            super.onCancel();
//            tvMsg.setText("取消請求");
        }

        @Override
        public void onReLogin() {
            toLogin();
        }
    };

    @Override
    protected void initEvent() {
        Log.e("tag", "initEvents: " );
        //登录
        mLoginBtnTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(MainActivity.class);
            }
        });
    }
}
